package com.zzyl.nursing.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.vo.TimeSoltVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 预约信息Mapper接口
 *
 * @author Katana
 * @date 2025-05-23
 */
@Mapper
public interface ReservationMapper extends BaseMapper<Reservation> {
    /**
     * 查询预约信息
     *
     * @param id 预约信息主键
     * @return 预约信息
     */
    public Reservation selectReservationById(Long id);
    
    /**
     * 查询预约信息列表
     *
     * @param reservation 预约信息
     * @return 预约信息集合
     */
    public List<Reservation> selectReservationList(Reservation reservation);
    
    /**
     * 新增预约信息
     *
     * @param reservation 预约信息
     * @return 结果
     */
    public int insertReservation(Reservation reservation);
    
    /**
     * 修改预约信息
     *
     * @param reservation 预约信息
     * @return 结果
     */
    public int updateReservation(Reservation reservation);
    
    /**
     * 删除预约信息
     *
     * @param id 预约信息主键
     * @return 结果
     */
    public int deleteReservationById(Long id);
    
    /**
     * 批量删除预约信息
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteReservationByIds(Long[] ids);
    
    /**
     * 查询当天取消预约数量
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param userId    用户ID
     * @return 数量
     */
    @Select("select count(1) from reservation where status = 2 and update_by = #{userId} and update_time between #{startTime} and #{endTime} ")
    Integer cancelledCount(@Param("startTime") LocalDateTime startTime,@Param("endTime") LocalDateTime endTime,@Param("userId") Long userId);
    
    /**
     * 根据时间统计预约量
     * select time, 6 - count(*) as count from reservation
     * where time between '2022-03-01' and '2022-03-31'
     * and status != 2 group by time;
     *
     * @param
     * @return 结果
     */
    @Select("select time, 6 - count(*) as count from reservation where time between #{startTime} and #{endTime} and status != 2 group by time")
    List<TimeSoltVo> countByTime(@Param("startTime") LocalDateTime startTime,@Param("endTime") LocalDateTime endTime);
}
